package com.bobaini.springcloud.utils;

import lombok.extern.slf4j.Slf4j;
import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.impl.DefaultMapperFactory;

import java.util.Collection;
import java.util.List;

/**
 * @author: liuyi
 * ClassName: Test
 * Version: 1.0.0
 * DateTime: 2021/03/31-10:36:00
 * Description: TODO
 */
@Slf4j
public class BeanConvertUtils {

    private static final MapperFacade mapperFacade = new DefaultMapperFactory.Builder().build().getMapperFacade();

    public static <S, T> T commonConvert(S s, Class<T> tClass) {
        return mapperFacade.map(s, tClass);
    }

    public static <S, T> void commonConvert(S s, T t) {
        if (s == null || t == null) {
            return;
        }
        mapperFacade.map(s, t);
    }

    public static <S, T> List<T> commonConvertList(Collection<S> s, Class<T> tClass) {
        return mapperFacade.mapAsList(s, tClass);
    }
}
